﻿using System;
using UnityEditor;
using UnityEngine;

public class USWelcomeScreenWindow : EditorWindow
{
    private Texture CommunityLogo;
    private Texture DocumentationLogo;
    private static string editorPrefsShowWelcome = ("uSequencer - Welcome Screen V" + USUpgradePaths.CurrentVersionNumber);
    private Texture FeedbackLogo;
    private GUIStyle Heading1Style;
    private GUIStyle NormalStyle;
    private GUIStyle SubHeading1Style;
    private GUIStyle SubHeading2Style;
    private Texture USeqLogo;
    private GUISkin USeqSkin;
    private Texture VideosLogo;
    private Texture WebsiteLogo;

    private bool LoadAssets()
    {
        if ((((this.USeqLogo == null) || (this.DocumentationLogo == null)) || ((this.VideosLogo == null) || (this.FeedbackLogo == null))) || (this.WebsiteLogo == null))
        {
            this.USeqLogo = Resources.Load("IconAlt2", typeof(Texture)) as Texture;
            this.DocumentationLogo = Resources.Load("IconDocumentation", typeof(Texture)) as Texture;
            this.VideosLogo = Resources.Load("IconVideos", typeof(Texture)) as Texture;
            this.FeedbackLogo = Resources.Load("IconFeedback", typeof(Texture)) as Texture;
            this.CommunityLogo = Resources.Load("IconCommunity", typeof(Texture)) as Texture;
            this.WebsiteLogo = Resources.Load("IconWebsite", typeof(Texture)) as Texture;
            this.USeqSkin = USEditorUtility.USeqSkin;
            if ((((this.USeqLogo == null) || (this.DocumentationLogo == null)) || ((this.VideosLogo == null) || (this.FeedbackLogo == null))) || ((this.WebsiteLogo == null) || (this.USeqSkin == null)))
            {
                return false;
            }
            this.Heading1Style = this.USeqSkin.GetStyle("Heading1");
            if (this.Heading1Style == null)
            {
                return false;
            }
            this.SubHeading1Style = this.USeqSkin.GetStyle("SubHeading1");
            if (this.SubHeading1Style == null)
            {
                return false;
            }
            this.SubHeading2Style = this.USeqSkin.GetStyle("SubHeading2");
            if (this.SubHeading2Style == null)
            {
                return false;
            }
            this.NormalStyle = this.USeqSkin.GetStyle("Normal");
            if (this.NormalStyle == null)
            {
                return false;
            }
        }
        return true;
    }

    private void OnGUI()
    {
        if (!EditorPrefs.HasKey(editorPrefsShowWelcome))
        {
            EditorPrefs.SetBool(editorPrefsShowWelcome, true);
        }
        if (!this.LoadAssets())
        {
            Debug.LogWarning("There was a problem loading assets, the welcome screen will not display correctly.");
        }
        else
        {
            GUILayout.BeginVertical(new GUILayoutOption[0]);
            int num = 100;
            bool flag = false;
            Rect screenRect = new Rect(0f, 0f, base.position.width, 107f);
            GUILayout.BeginArea(screenRect, string.Empty, !flag ? string.Empty : "box");
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            GUILayout.BeginVertical(new GUILayoutOption[0]);
            GUILayout.FlexibleSpace();
            GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.MinWidth(base.position.width) };
            GUILayout.Label("Welcome to uSequencer!", this.Heading1Style, options);
            GUILayout.Space(6f);
            GUILayoutOption[] optionArray2 = new GUILayoutOption[] { GUILayout.MinWidth(base.position.width) };
            GUILayout.Label("You have in your hands a powerful sequencer", this.SubHeading1Style, optionArray2);
            GUILayoutOption[] optionArray3 = new GUILayoutOption[] { GUILayout.MinWidth(base.position.width) };
            GUILayout.Label("we cannot wait to see what you produce.", this.SubHeading1Style, optionArray3);
            GUILayout.FlexibleSpace();
            GUILayout.EndVertical();
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            GUILayout.EndArea();
            num = 150;
            screenRect.y += screenRect.height;
            screenRect.height -= 20f;
            GUILayout.BeginArea(screenRect, string.Empty, !flag ? string.Empty : "box");
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            GUILayout.Space(10f);
            if (GUILayout.Button(this.DocumentationLogo, new GUILayoutOption[0]))
            {
                this.OpenDocumentationWindow();
            }
            GUILayout.Space(10f);
            GUILayout.BeginVertical(new GUILayoutOption[0]);
            GUILayout.Space(4f);
            GUILayoutOption[] optionArray4 = new GUILayoutOption[] { GUILayout.MinWidth(base.position.width - num) };
            GUILayout.Label("Documentation", this.SubHeading2Style, optionArray4);
            GUILayout.Space(6f);
            GUILayoutOption[] optionArray5 = new GUILayoutOption[] { GUILayout.MinWidth(base.position.width - num) };
            GUILayout.Label("For a full overview of the uSequencer, including a", this.NormalStyle, optionArray5);
            GUILayoutOption[] optionArray6 = new GUILayoutOption[] { GUILayout.MinWidth(base.position.width - num) };
            GUILayout.Label("reference for adding your own events, check out our", this.NormalStyle, optionArray6);
            GUILayoutOption[] optionArray7 = new GUILayoutOption[] { GUILayout.MinWidth(base.position.width - num) };
            GUILayout.Label("online documentation", this.NormalStyle, optionArray7);
            GUILayout.FlexibleSpace();
            GUILayout.EndVertical();
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            GUILayout.EndArea();
            screenRect.y += screenRect.height;
            GUILayout.BeginArea(screenRect, string.Empty, !flag ? string.Empty : "box");
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            GUILayout.Space(10f);
            if (GUILayout.Button(this.VideosLogo, new GUILayoutOption[0]))
            {
                this.OpenVideosWindow();
            }
            GUILayout.Space(10f);
            GUILayout.BeginVertical(new GUILayoutOption[0]);
            GUILayout.Space(10f);
            GUILayoutOption[] optionArray8 = new GUILayoutOption[] { GUILayout.MinWidth(base.position.width - num) };
            GUILayout.Label("Videos", this.SubHeading2Style, optionArray8);
            GUILayout.Space(6f);
            GUILayoutOption[] optionArray9 = new GUILayoutOption[] { GUILayout.MinWidth(base.position.width - num) };
            GUILayout.Label("There are a number of video tutorials covering many", this.NormalStyle, optionArray9);
            GUILayoutOption[] optionArray10 = new GUILayoutOption[] { GUILayout.MinWidth(base.position.width - num) };
            GUILayout.Label("topics, from beginner to advanced", this.NormalStyle, optionArray10);
            GUILayout.FlexibleSpace();
            GUILayout.EndVertical();
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            GUILayout.EndArea();
            screenRect.y += screenRect.height;
            GUILayout.BeginArea(screenRect, string.Empty, !flag ? string.Empty : "box");
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            GUILayout.Space(10f);
            if (GUILayout.Button(this.FeedbackLogo, new GUILayoutOption[0]))
            {
                this.OpenFeedbackWindow();
            }
            GUILayout.Space(10f);
            GUILayout.BeginVertical(new GUILayoutOption[0]);
            GUILayout.Space(10f);
            GUILayoutOption[] optionArray11 = new GUILayoutOption[] { GUILayout.MinWidth(base.position.width - num) };
            GUILayout.Label("Feedback", this.SubHeading2Style, optionArray11);
            GUILayout.Space(6f);
            GUILayoutOption[] optionArray12 = new GUILayoutOption[] { GUILayout.MinWidth(base.position.width - num) };
            GUILayout.Label("Your feedback is very important to use. If you want a", this.NormalStyle, optionArray12);
            GUILayoutOption[] optionArray13 = new GUILayoutOption[] { GUILayout.MinWidth(base.position.width - num) };
            GUILayout.Label("new feature for uSequencer, you can request it here.", this.NormalStyle, optionArray13);
            GUILayout.FlexibleSpace();
            GUILayout.EndVertical();
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            GUILayout.EndArea();
            screenRect.y += screenRect.height;
            GUILayout.BeginArea(screenRect, string.Empty, !flag ? string.Empty : "box");
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            GUILayout.Space(10f);
            if (GUILayout.Button(this.CommunityLogo, new GUILayoutOption[0]))
            {
                this.OpenCommunityWindow();
            }
            GUILayout.Space(10f);
            GUILayout.BeginVertical(new GUILayoutOption[0]);
            GUILayout.Space(10f);
            GUILayoutOption[] optionArray14 = new GUILayoutOption[] { GUILayout.MinWidth(base.position.width - num) };
            GUILayout.Label("Community", this.SubHeading2Style, optionArray14);
            GUILayout.Space(6f);
            GUILayoutOption[] optionArray15 = new GUILayoutOption[] { GUILayout.MinWidth(base.position.width - num) };
            GUILayout.Label("The uSequencer community is gorwing daily, visit the", this.NormalStyle, optionArray15);
            GUILayoutOption[] optionArray16 = new GUILayoutOption[] { GUILayout.MinWidth(base.position.width - num) };
            GUILayout.Label("forum and join in with the conversation", this.NormalStyle, optionArray16);
            GUILayout.FlexibleSpace();
            GUILayout.EndVertical();
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            GUILayout.EndArea();
            screenRect.y += screenRect.height;
            GUILayout.BeginArea(screenRect, string.Empty, !flag ? string.Empty : "box");
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            GUILayout.Space(10f);
            if (GUILayout.Button(this.WebsiteLogo, new GUILayoutOption[0]))
            {
                this.OpenWebsiteWindow();
            }
            GUILayout.Space(10f);
            GUILayout.BeginVertical(new GUILayoutOption[0]);
            GUILayout.Space(10f);
            GUILayoutOption[] optionArray17 = new GUILayoutOption[] { GUILayout.MinWidth(base.position.width - num) };
            GUILayout.Label("Website", this.SubHeading2Style, optionArray17);
            GUILayout.Space(6f);
            GUILayoutOption[] optionArray18 = new GUILayoutOption[] { GUILayout.MinWidth(base.position.width - num) };
            GUILayout.Label("The official uSequencer website is packed with ", this.NormalStyle, optionArray18);
            GUILayoutOption[] optionArray19 = new GUILayoutOption[] { GUILayout.MinWidth(base.position.width - num) };
            GUILayout.Label("information.", this.NormalStyle, optionArray19);
            GUILayout.FlexibleSpace();
            GUILayout.EndVertical();
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            GUILayout.EndArea();
            GUILayout.FlexibleSpace();
            GUILayoutOption[] optionArray20 = new GUILayoutOption[] { GUILayout.MinWidth(base.minSize.x) };
            bool flag2 = EditorGUILayout.Toggle("Show Welcome Screen?", EditorPrefs.GetBool(editorPrefsShowWelcome), optionArray20);
            EditorPrefs.SetBool(editorPrefsShowWelcome, flag2);
            GUILayout.EndVertical();
        }
    }

    private void OpenCommunityWindow()
    {
        Application.OpenURL("http://www.usequencer.freeforums.org");
    }

    private void OpenDocumentationWindow()
    {
        Application.OpenURL("http://www.usequencer.com/manual");
    }

    private void OpenFeedbackWindow()
    {
        Application.OpenURL("http://usequencer.uservoice.com/");
    }

    private void OpenVideosWindow()
    {
        Application.OpenURL("http://www.youtube.com/user/artofsettling/videos");
    }

    private void OpenWebsiteWindow()
    {
        Application.OpenURL("http://www.usequencer.com");
    }

    public static void OpenWindow(bool force)
    {
        if ((force || !EditorPrefs.HasKey(editorPrefsShowWelcome)) || EditorPrefs.GetBool(editorPrefsShowWelcome))
        {
            USWelcomeScreenWindow window = EditorWindow.GetWindow(typeof(USWelcomeScreenWindow), true, "Welcome", true) as USWelcomeScreenWindow;
            window.position = new Rect(350f, 150f, 400f, 570f);
        }
    }
}

